package gbench.sandbox.record;

import static gbench.common.tree.LittleTree.IRecord.L;

import java.time.LocalDateTime;
import java.util.stream.Stream;

import org.junit.jupiter.api.Test;

import gbench.common.matlib.MatlibCanvas.NVec;
import gbench.common.tree.LittleTree;
import gbench.common.tree.LittleTree.IRecord;

import static gbench.common.matlib.MatlibCanvas.println;
import static gbench.common.tree.LittleTree.IRecord.*;

/**
 * IRecordBuilder 的使用演示
 * @author gbench
 *
 */
public class JunitBuilder {

    @Test
    public void foo() {
        final var r = new IRecord.Builder("id,name").get((Object[]) "1,张三".split(","));
        println(r);
        
        final var r1 = new IRecord.Builder("id,name").get(3);
        println(r1);
        
        final var r2 = new IRecord.Builder("#id,~mobile,32name,64address,birth,128password");
        println(r2.get2(1,"13120751773","张三","上海",LocalDateTime.now()));
        
        final var r3 = new IRecord.Builder((i,v)->LittleTree.excelname(i)+"_"+i);
        println(r3.get(NVec.of(100,i->i).toArray()));
        
        println(Stream.of(1,2,3,4,5).collect(IRecord.rbclc((i,v)->LittleTree.excelname(i), e->"-".repeat(e))));
        println(Stream.of(1,2,3,4,5).collect(IRecord.rbclc((i,v)->LittleTree.excelname(i))));
    }

    @Test
    public void bar() {
        
        final var hierachies = L( // 层级结构数据 id name pid
            "0   中国          -",

            "1   北京          0", 
            "1.1   东城区          1",
            "1.2   朝阳区          1",

            "2   上海          0", 
            "2.1   长宁区          2",
            "2.2   徐汇区          2",

            "3   天津          0", 
            "4   重庆          0");

        // id name pid 列表
        final var builder = IRecord.builder("id,name,pid");
        final var tree = hierachies.stream().map(line -> line.split("\\s+")).map(builder::get)
            .collect(llclc(LittleTree::buildTree));

        tree.forEach(e -> {
            println("\t".repeat(e.getLevel()-1) + e);
        });
    }

}
